<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>baoge-1</title>
  </head>
  <body>
    <div id="app">
        <input type="text" v-model="inputValue">
        <button @click="handleBtnClick">提交</button>
        <ul>
            <!-- <li v-for="item in list">{{item}}</li> -->
            <todo-item 
                v-bind:content="item" 
                :index="index" 
                v-for="(item,index) in list" 
                :key = "item.index" 
                @delete="handelItemDelete">
            </todo-item>
        </ul>
    </div>
    <script src="js/vue.js"></script>
    <script>
    Vue.component("TodoItem",{
        props:['content','index'],
        template:'<li @click="handleItemClick">{{content}}</li>',
        methods:{
            handleItemClick:function() {
               this.$emit("delete",this.index)
            }
        }
    })  
    var app = new Vue({
        el:'#app',
        data:{
            inputValue:'',
            list:[]
        },
        methods:{
            handleBtnClick:function () {
               this.list.push(this.inputValue),
               this.inputValue=""
            },
            handelItemDelete:function(index) {
                this.list.splice(index,1)
            }
        }
    })
    </script>
  </body>
</html>
